# -*- coding: UTF-8 -*-
"""
Course:        CS408 Computer Science Project B, TEAM 1
Semester:      2010 SPRING
Project:       DOHN(Web-based Account Book System)

File:          views.py
Description:   View class.
Class:         View

Author:        SungHyuk Im
"""


import string
#import mod_python

import sessions
import utils
import transactions


class View:
    """
    Super class of every view classes.
    """
    def show_index_window(self, req):
        """
        @summary: Show index window.
        @param req: request 
        @return: Transaction list page(signed in), Sign in page(not signed in)
        """
        
        if sessions.check_signed(req):
            trx_obj = transactions.TransactionView()
            return trx_obj.show_index_window(req)
        else:
            return self.show_signin_window(req)
    
    def show_signin_window(self, req):
        """
        @summary: show index window(login page).
        @param req: request 
        @return: Sign in page
        """
        #src_path = utils.get_abs_path() + "/signin.src"
        src_path = utils.get_abs_path() + "/html/main.html"
        src = utils.get_file_content(src_path)
        return src
    
    def show_signin_window_error(self, req):
        """
        @summary: show index window(login page) with error message.
        @param req: request
        @return: Sign in page with login error message 
        
        @deprecated: It is replaced by other! No longer used!!
        """
        # v1
#        src_path = utils.get_abs_path() + "/html/main_error.html"
#        src = utils.get_file_content(src_path)
#        return src
        
        # v2
#        src = utils.get_main_with_msg("Login Error!\nCheck ID or Password.")
#        
#        file_path = utils.get_abs_path() + "main_witherror.html"
#        afile = file(file_path, "w")
#        afile.write(src)
#        afile.close()
#        
#        mod_python.util.redirect(req, file_path)
        pass